<?php

namespace component\system\system_message;

use common\logic\Logic;


class SystemMessage extends Logic
{

    /**
     * 系统消息
     * @var int
     */
    const TYPE_SYSTEM = 1;

    /**
     * @var array
     */
    public $fields = [
        'id',
        'type',
        'user_id',
        'title',
        'message',
        'read_time',
        'create_time',
    ];

    /**
     * @return SystemMessageModel|\think\Model
     */
    protected function model()
    {
        return new SystemMessageModel();
    }


    /**
     * @param $user_id
     * @param null $read_time
     * @return array|bool|\think\Collection|\think\Paginator
     */
    public function getListByUserId($user_id, $read_time = null)
    {
        if (empty($user_id)) {
            return false;
        }

        $params = [
            'user_id' => $user_id,
        ];

        if (null !== $read_time) {
            if ($read_time == 0) {
                $params['read_time'] = 0;
            } else {
                $params[] = [
                    'read_time', '<>', 0
                ];
            }
        }

        return $this->select($params);
    }
}